<!DOCTYPE html>
<html>
<head>
<title>地区管理</title>
#include("../include/common.html")
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>地区管理</h5>
            </div>
            <div class="ibox-content">
                <!-- 列表 start -->
                <div class="form-horizontal clear">
                
                    <div class="form-group">
                        <div class="col-sm-8">
                            <a class="btn btn-primary" href="add#if(parent??)?parentId=#(parent.id)#end"><i class="fa fa-plus"></i> 添加</a>
                       		#if(parent??)
								#if(parent.parent??)
									<a class="btn btn-primary" href="list?parentId=#(parent.parent.id)"><i class="fa fa-arrow-up"></i> 上级地区</a>
								#else
									<a class="btn btn-primary" href="list"><i class="fa fa-arrow-up"></i> 上级地区</a>
								#end
							#end
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-bordered" id="listTable">
                            <thead>
                                <tr>
                                    <th colspan="5" class="green" style="text-align: center;">
										#if(parent??)上级地区 - #(parent.name) #else 顶级地区  #end
									</th>
                                </tr>
                            </thead>
                            <tbody>
                            #for(area : areas)
                                #if(for.index%5==0) <tr>  #end
                                    <td>
                                         <a href="list?parentId=#(area.id)" title="查看">#(area.name)</a>
                                         <a href="edit?id=#(area.id)">[编辑]</a>
                                         <a href="javascript:;" class="delete" val="#(area.id)">[删除]</a>
                                     </td>
                                #if((for.index+1)%5==0) </tr>  #end
                            #end
							#if(areas.size()==0)
								<tr>
									<td colspan="5" style="text-align: center; color: red;">
										无下级地区 <a href="add#if(parent??)?parentId=#(parent.id)#end" class="silver">添加</a>
									</td>
								</tr>
							#end
                            </tbody>
                        </table>
                    </div>
                </div>
                <!-- 列表 end -->
            </div>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
$().ready(function() {

	var $delete = $("#listTable a.delete");
	
	// 删除
	$delete.click(function() {
		var $this = $(this);
		if(confirm("您确定要删除吗？")){
			$.ajax({
				url: "delete",
				type: "POST",
				data: {id: $this.attr("val")},
				dataType: "json",
				cache: false,
				success: function(data) {
					if (data.type == "success") {
						$this.parent().html("&nbsp;");
					}
				}
			});
		}
		return false;
	});

});
</script>